package com.elinkway.infinitemovies.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.le123.ysdq.R;

public class BorderedRelativeLayout extends RelativeLayout {

	/**
	 * 边框颜色
	 * e.g. app:borderColor="#33000000"
	 */
	private int borderColor = 0x33000000;
	/**
	 * 边框宽度
	 * e.g. app:borderWidth = "1dp"
	 */
	private float borderWidth = 1.0f;
	
	public BorderedRelativeLayout(Context context) {
		this(context,null);
		// TODO Auto-generated constructor stub
	}

	public BorderedRelativeLayout(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		setWillNotDraw(false);
	    TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.BorderedRelativeLayout);
	    borderColor = a.getColor(R.styleable.BorderedRelativeLayout_borderColor, 0x00000000);
	    borderWidth = a.getDimension(R.styleable.BorderedRelativeLayout_borderWidth, 1.0f);
	    a.recycle();
		// TODO Auto-generated constructor stub
	}

	public BorderedRelativeLayout(Context context, AttributeSet attrs) {
		this(context, attrs,0);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		Rect rec=canvas.getClipBounds();
		rec.bottom--;
		rec.right--;
//		rec.left--;
//		rec.top--;
		Paint paint=new Paint();
		paint.setColor(borderColor);
		paint.setStrokeWidth(borderWidth);
		paint.setStyle(Paint.Style.STROKE);
		canvas.drawRect(rec, paint);
	}
}
